<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件驱动</title>
</head>

<body>
    <div>
        <div>
            数量 <input type="text" id="goodsnum" />
        </div>
        <div>
            价格 <input type="text" id="goodsprice" />
        </div>
        <div>
            小计 <span id="total"></span>
        </div>

    </div>
</body>
<script>
    let goodsnumInput = document.getElementById("goodsnum");
    let goodspriceInput = document.getElementById("goodsprice");
    let totalSpan = document.getElementById("total");

    let goodsinfo = {//表示一个对象


    }
    let _goodsnum = 0;
    let _goodsprice = 0;
    Object.defineProperty(goodsinfo, "goodsnum", {
        get() {//取值
            return _goodsnum;

        },
        set(num) {//赋值
            _goodsnum = num;
            complier();//编译器

        }

    })
    Object.defineProperty(goodsinfo, "goodsprice", {
        get() {//取值
            return _goodsprice;

        },
        set(price) {//赋值
            _goodsprice = price;
            complier();
        }

    })

    function complier() {
        totalSpan.innerHTML = goodsinfo.goodsnum * goodsinfo.goodsprice;
    }


    goodsnumInput.oninput = function () {

        goodsinfo.goodsnum = goodsnumInput.value;//赋值 给对象的属性  //this.num = this.num -10
        //??? 对象赋值 页面能变  中间一定发生了什么
        //需要知道对象的属性发生了变化  并且需要进行捕获

    }
    goodspriceInput.oninput = function () {
        goodsinfo.goodsprice = goodspriceInput.value;//对象的属性赋值  // this.num++;

    }


</script>

</html>